Add support for local LLM - #133
Open
foureight84 wants to merge 1 commit into
Open
Conversation
Adds a `localOpenAICompat` provider pointing at any OpenAI-Chat-Completions server the user runs themselves — Ollama, llama.cpp, vLLM, SGLang, LM Studio — so a coach conversation can happen without health data leaving the network. Ported from PulseLoopAndroid saksham2001#51 including the fixes from its review. Structurally the client is MiniMaxClient — same Responses→Chat translation, same accumulate-across-send statefulness, same fresh-client-per-turn contract — with four differences, each forced by something local backends do: - The API key is optional. Every engine in scope runs unauthenticated by default, so a blank key omits the Authorization header and readiness is a base URL that passes LocalEndpoint.validate. Not "non-empty": Settings persists as the user types, so a blank-check would flip the coach to "Active" on the first character and fail every turn afterwards. - `developer` folds into `system`, and all system turns merge into one leading message. SGLang 400s on a role outside its pydantic Literal; many local chat templates need the system turn first and singular. - Capabilities are declared, not assumed. vLLM 400s on `tools` without --enable-auto-tool-choice; LM Studio has no json_object mode. Detect probes a plain baseline request first, then tools and response_format, so a 4xx means "this field is refused" rather than "this request is refused" — and only a conclusive verdict overwrites a setting the user chose by hand. - A long, configurable timeout, and no redirects. Privacy note, per CONTRIBUTING: this changes what leaves the device only by making it possible for nothing to. Cleartext is three layers. NSAllowsLocalNetworking re-permits cleartext for local destinations only (never NSAllowsArbitraryLoads), LocalEndpoint.validate explains a bad host in the Settings field instead of failing opaquely at request time, and LocalHTTP refuses redirects — validate() vets the URL typed, not where the request lands, and a 307 off the LAN would resend the health-context body in the clear. New under Coach/Local/: LocalEndpoint, LocalHTTP, LocalModelCatalog, LocalCapabilityProbe, LocalOpenAICompatClient, LocalLLMKeychainStore, and LocalServerSettingsSection (its own view — the probe state should die with the provider selection, and CoachSettingsSection was at SwiftLint's type_body_length ceiling). The target uses a file-system-synchronized group, so no project.pbxproj change. Docs: design and the per-engine support matrix in docs/local-llm-coach.md (added to the mkdocs nav); README, docs/platforms/ios-vs-android.md and docs/project/privacy.md updated to list the provider. swiftlint: 0 errors. 1108 tests, 0 failures (43 new). Not yet verified against a real server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
localOpenAICompatprovider pointing at any OpenAI-Chat-Completions server the user runs themselves — Ollama, llama.cpp, vLLM, SGLang, LM Studio — so a coach conversation can happen without health data leaving the network. Ported from PulseLoopAndroid #51 including the fixes from its review.Structurally the client is MiniMaxClient — same Responses→Chat translation, same accumulate-across-send statefulness, same fresh-client-per-turn contract — with four differences, each forced by something local backends do:
developerfolds intosystem, and all system turns merge into one leading message. SGLang 400s on a role outside its pydantic Literal; many local chat templates need the system turn first and singular.toolswithout --enable-auto-tool-choice; LM Studio has no json_object mode. Detect probes a plain baseline request first, then tools and response_format, so a 4xx means "this field is refused" rather than "this request is refused" — and only a conclusive verdict overwrites a setting the user chose by hand.Privacy note, per CONTRIBUTING: this changes what leaves the device only by making it possible for nothing to. Cleartext is three layers. NSAllowsLocalNetworking re-permits cleartext for local destinations only (never NSAllowsArbitraryLoads), LocalEndpoint.validate explains a bad host in the Settings field instead of failing opaquely at request time, and LocalHTTP refuses redirects — validate() vets the URL typed, not where the request lands, and a 307 off the LAN would resend the health-context body in the clear.
New under Coach/Local/: LocalEndpoint, LocalHTTP, LocalModelCatalog, LocalCapabilityProbe, LocalOpenAICompatClient, LocalLLMKeychainStore, and LocalServerSettingsSection (its own view — the probe state should die with the provider selection, and CoachSettingsSection was at SwiftLint's type_body_length ceiling). The target uses a file-system-synchronized group, so no project.pbxproj change.
Docs: design and the per-engine support matrix in docs/local-llm-coach.md (added to the mkdocs nav); README, docs/platforms/ios-vs-android.md and docs/project/privacy.md updated to list the provider.
swiftlint: 0 errors. 1108 tests, 0 failures (43 new). Not yet verified against a real server.
Summary
Related issues
Type of change
How was this tested?
PulseLoopTests)⌘Uin Xcode)-seedDemo YES, no hardware)Privacy & data
Screenshots / recordings
Checklist